package com.zj.study.utils.validation.validator.size;


import com.zj.study.utils.validation.annotation.ValidateSupport;
import com.zj.study.utils.validation.annotation.constraint.Size.List;
import java.util.Collection;
import org.springframework.lang.NonNull;

/**
 * @author 谭耀飞
 * @since 2021.01.0
 */
@ValidateSupport(Collection.class)
public class SizeListValidatorForCollection extends AbstractSizeListValidator<Collection<?>> {

  @Override
  boolean compare(@NonNull List sizes, @NonNull Collection<?> value) {
    for (var size : sizes.value()) {
      if (size.min() <= value.size() && value.size() <= size.max()) {
        return true;
      }
    }
    return false;
  }

}
